<template>
  <!-- 右边 -->
  <div>
    <div class="aside">
      <h4>相关攻略</h4>
      <el-row type="flex" class="post" v-for="(item,index) in list" :key="index">
        <img
          :src="item.images[0] || 'https://ss0.baidu.com/73x1bjeh1BF3odCf/it/u=2032834204,2199940577&fm=85&s=C8011D72414E674D447C59D90300C0B2'"
          alt
        />
        <div class="post-text">
          <div>{{item.title}}</div>
          <p>
            <span>{{ item.created_at | format}}</span>
            <span>阅读：{{item.watch || 0}}</span>
          </p>
        </div>
      </el-row>
    </div>
  </div>
</template>

<script>
import moment from "moment";
export default {
  data() {
    return {
      list: {}
    };
  },
  mounted() {
    this.$axios({
      url: "/posts/recommend",
      params: {
        id: this.$route.query.id
      }
    }).then(res => {
      const { data } = res.data;
      console.log(data);
      this.list = data;
    });
  },
  filters: {
    //   转时间格式
    format(val) {
      val = moment(val).format("YYYY-MM-DD hh:mm");
      return val;
    }
  },
  methods: {}
};
</script>

<style scoped lang='less'>
.aside {
  display: flex;
  flex-direction: column;
  h4 {
    font-size: 18px;
    font-weight: normal;
    padding-bottom: 10px;
    border-bottom: 1px solid #ddd;
  }
  .post {
    padding: 20px 0;
    justify-content: space-around;
    border-bottom: 1px solid #ddd;
    img {
      width: 100px;
      height: 80px;
    }

    .post-text {
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      width: 170px;
      div {
        font-size: 16px;
        height: 45px;
        overflow: hidden;
      }
      p {
        font-size: 12px;
        color: #999;
        max-height: 32px;
        width: 100%;
        overflow: hidden;
      }
    }
  }
}
</style>